home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / T / TurboT folder / HelloTurboTabby.p < prev    next >
Encoding:
Text File  |  1989-12-17  |  13.7 KB  |  376 lines  |  [TEXT/TPAS]

  1. unit HelloTurboTabby(1);
  2.  
  3. { Written by Pete Johnson, Glassell Park BBS, 213-258-7649                       }
  4.  
  5.  
  6. { ------  ML                                                      }
  7.  
  8. { Modified by Michael Lininger, Aurora Borealis BBS, 614-471-6209 }
  9.  
  10.      { Modifications by Michael Lininger, include :               }
  11.      { Cleanup and port so unit works with Turbo Pacal (Mac)      }
  12.      
  13.      { • This souce and compiled unit are for use with Turbo Pacal}
  14.      { • Unit has been renamed  'HelloTurboTabby'                 }
  15.      { • In the following comments, replace the word LightSpeed   }
  16.      {   with Turbo                                               }
  17.      
  18. { ------ ML                                                       }
  19.  
  20.  
  21. { Source for a LightSpeed Pascal unit which handles the Tabby     }
  22. { launch.next    file and returns the name of the next application   }
  23. { to launch in a variable called NextLaunch.                                                          }
  24.  
  25. { This source code is being made public in the hopes that it will }
  26. { lead to more    and better Tabby applications. I ask only that you }
  27. { credit me with a thanks    if you incorporate any or all of this   }
  28. { code in an application.                                                     }
  29.  
  30. { I have no doubt that this code could be made better. If you     }
  31. { improve on it,    please share your ideas.                                                          }
  32.  
  33. { If you're not using LightSpeed Pascal, you're on your own. I    }
  34. { don't know    any other Pascal compilers. I'm sure someone other   }
  35. { than me can help you    if you need to convert this code for Turbo,}
  36. { TML or Apple's MPW Pascal.                                            }
  37.  
  38. { Thanks to Erik Selberg, who has been a real help.                                 }
  39.  
  40. { How to use this code:                                                                               }
  41.  
  42. {  <1> Create a Turbo Pascal Project                                                      }
  43. {  <2> Add the HelloTurboTabby to you units file, internal to     }
  44. {      Turbo, use the Unit's mover application to do this                  }
  45. {  <3> Create your own additional files                                                      }
  46.  
  47.  
  48. { ------ ML                                                       }
  49.  
  50. { I have changed the STR resource form 500 to 1511, .ML.          }
  51.  
  52. { ------ ML                                                       }
  53.  
  54.  
  55. { You should include an STR resource 1511 in the Project: this    }
  56. { holds the name    of the default launch.next application (usually  }
  57. { 'Red Ryder Host').                                                       }
  58.  
  59. { Your main program Unit should include the following lines at    }
  60. { its start:                                                         }
  61.  
  62. {     uses                                                                                                  }
  63. {       ... any turbo units necessary ... , HelloTurboTabby;                        }
  64.  
  65. {   End the main procedure of your program as follows:                              }
  66.  
  67. {    HelloTabby;                                                                                         }
  68. {    if NextLaunch <> '' then                                                                      }
  69. {       LaunchNextAppl                                                  }
  70. {    end.                                                                                                      }
  71.  
  72.  
  73. {            ********** History **********                                                         }
  74.  
  75. { Modified March 11, 1989, to handle up to 100 events of < 32     }
  76. { chars apiece.                                                      }
  77. { Modified April 17,                                              } 
  78. {            May  6, 1989, to handle MultiFinder.                                }
  79. { Modified  June 11, 1989, to use Toolbox file calls.                               }
  80. { Modified  June 15, 1989, to use Tabby Setup name for 'BBS'            }
  81. { Modified  July 22, 1989, for additional error checking.                        }
  82.  
  83. { ------ ML                                                       }
  84.  
  85. { Modified   Dec 16, 1989, for use with Turbo Pacal .ML.          }
  86.  
  87. { ------ ML                                                       }
  88.  
  89.  
  90.  
  91. {     Range    checking options turned on, in compiler.                 }
  92. {$R+}
  93.  
  94. interface
  95.  
  96. { Internal Prefab libraries used by HelloTurboTabby               }
  97. uses MemTypes,QuickDraw,OSIntf,ToolIntf;
  98.  
  99. const
  100.      NULL = #0;
  101.         TAB = #9;
  102.         ENDLINE = #13;
  103.         SPACE = #32;
  104.  
  105. type
  106.         MyByte = byte;
  107.         OneString = STR255;
  108.         OneStringPtr = ^OneString;
  109.         OneStringHdl = ^OneStringPtr;
  110.  
  111. var
  112.         FileError: OSErr;
  113.         VRefNum, CurrentResFile, ErrorCode: integer;
  114.         VolName: STR255;
  115.         ErrorFlag: boolean;
  116.         NextAppHandle: StringHandle;
  117.  
  118. type
  119.      pLaunchStruct = ^LaunchStruct;
  120.         LaunchStruct = 
  121.         record
  122.                    pfName: StringPtr;
  123.                       param: INTEGER;
  124.                       LC: packed array[0..1] of CHAR;    { extended parameters:                            }
  125.                       extBlockLen: LONGINT;                          { number of bytes in ext = 6    }
  126.                       fFlags: INTEGER;                                     { Finder file info flags                    }
  127.                       launchFlags: LONGINT;                          { bit 31,30=1 for sublaunch, }
  128.                                              { others reserved            }
  129.          end;
  130.       
  131. var
  132.         NextLaunch: str255;
  133.         MultiFinder: boolean;
  134.  
  135. procedure LaunchNextAppl;
  136. procedure HelloTurboTabby;
  137.  
  138. implementation
  139.  
  140.  
  141. { Procedure #1 ReadConfig - This procedures reads the Config }
  142. { file to determine if MultiFinder or Finder is being used   }
  143. { ---------------------------------------------------------- }
  144.  
  145. procedure ReadConfig;
  146.  
  147. var
  148.      ConfigRefNum: integer;
  149.            logicalEOF, CharsToSend: longint;
  150.            MFByte: SignedByte;
  151.  
  152.  
  153. begin
  154.      MultiFinder := false;
  155.            CharsToSend := 1;
  156.            FileError := FSOpen('Config', vRefNum, ConfigRefNum);
  157.            if FileError = noErr then
  158.               begin
  159.                       FileError := GetEOF(ConfigRefNum, logicalEOF);
  160.                       if (FileError = noErr) and (logicalEOF = 349) then
  161.                          begin
  162.                                  FileError := SetFPos(ConfigRefNum, fsFromStart, 316);
  163.                                  FileError := FSRead(ConfigRefNum, CharsToSend, @MFByte);
  164.                                  if MFByte <> 0 then
  165.                                          MultiFinder := true;
  166.                          end;        {    if (FileError = noErr) and (logicalEOF = 349)    }
  167.               end;    {    if FileError = noErr    }
  168.            FileError := FSClose(ConfigRefNum);
  169. end;
  170.  
  171.  
  172.  
  173. { Function #1 Launchit - This function does the actual }
  174. { launch or sublaunch, in cause of MultiFinder.        }
  175. { Traps 205F, A9F2, 3E80                               }
  176. { ---------------------------------------------------- }
  177.  
  178. function Launchit (pLnch: pLaunchStruct): OSErr;
  179.  
  180. inline
  181.     $205F, $A9F2, $3E80;
  182.  
  183.  
  184.  
  185. { Procedure #2 LaunchNextAppl - This procedure sets up }
  186. { the necessary launch flags to be used by Lauchit.    }
  187. { ---------------------------------------------------- }
  188.  
  189. procedure LaunchNextAppl;
  190.  
  191. var
  192.            pMyLaunch: pLaunchStruct;
  193.            myLaunch: LaunchStruct;
  194.            MyPB: CInfoPBRec;
  195.  
  196. begin { Start Structure LaunchNextAppl }
  197.  
  198.      with MyPB do { Start Structure MyPB }
  199.               begin
  200.                       ioNamePtr := @NextLaunch;
  201.                    ioVRefNum := vRefNum;
  202.                    ioFDirIndex := 0;
  203.                    ioDirID := 0;
  204.               end;            {    End Structure myPB    }
  205.            FileError := PBGetCatInfo(@MyPB, false);
  206.  
  207.            pMyLaunch := @myLaunch;
  208.            with pMyLaunch^ do { Start Structure pMyLaunch^ }
  209.               begin
  210.                       pfName := @NextLaunch;
  211.                       param := 0;
  212.                       LC[0] := 'L';
  213.                       LC[1] := 'C';
  214.                       extBlockLen := 6;
  215.                       fFlags := myPB.ioFlFndrInfo.fdFlags;
  216.                       if MultiFinder then
  217.                            LaunchFlags := $C0000000    {    set BOTH high bits for a sublaunch    }
  218.                        else
  219.                               LaunchFlags := $00000000;    {    just launch, then quit    }
  220.      end;                    {    End Structure pMyLaunch^    }
  221.            FileError := Launchit(pMyLaunch);
  222.  
  223. end; {End Structure LaunchNextAppl }
  224.  
  225.  
  226.  
  227. { Procedure #3 - HelloTurboTabby.  This procedure looks for a Tabby   }
  228. { launch.next file. If it's found, it extracts the events, which are  }
  229. { comma delimited, saves the first one    for the next launch and        }
  230. { rewrites the file from event #2 to the last    event back to the disk. }
  231.  
  232. { If it finds only one event, it kills the launch.next file.                   }
  233.  
  234. { If there are no events, it returns the application name contained   }
  235. { in STR 1511 as str255 NextLaunch, otherwise it uses NextLaunch to   }
  236. { hold the first entry in the launch.next script.                           }
  237.  
  238. { Before returning, it also checks that the NextLaunch application    }
  239. { exists    by trying to    open it. If the open attempt fails, it returns  }
  240. { NextLaunch    as an empty string.                                                                          }
  241.  
  242. procedure HelloTurboTabby;
  243.  
  244. type
  245.            HundredEvents = array[1..100] of string[32];
  246.            ManyChars = packed array[1..3300] of char;    {    Can hold 100 32-length }
  247.                                                 { events, commas and one }
  248.                                                 { <CR>.                     }
  249.  
  250. var
  251.            EventCounter, EventLimit, LNRefNum, LaunchCount: integer;
  252.            LNChar: char;
  253.            BBSByte: SignedByte;
  254.            TheChars: ManyChars;
  255.            Event: HundredEvents;
  256.            Events, ThisEvent, VolName, TempString, BBSName: str255;
  257.            logicalEOF, Quantity, CharIndex: longint;
  258.            CharCount, SetUpRef, SetUpCount: integer;
  259.            fndrInfo: FInfo;
  260.  
  261. begin { Start Structure HelloTurboTabby }
  262.  
  263.      FileError := GetVol(@VolName, vRefNum);        { Get volume ref # for }
  264.                                               { default volume.      }
  265.            Events := '';
  266.            for EventCounter := 1 to 100 do
  267.                    Event[EventCounter] := '';
  268.  
  269.            ThisEvent := '';
  270.            LNChar := chr(255);    {    Dummy value so we can spot }
  271.                          {  this first time through      }
  272.            NextAppHandle := GetString(1511);
  273.            NextLaunch := NextAppHandle^^;
  274.            ReadConfig; {    Read Host's Config File and see }
  275.                  { if we're running MultiFinder.      }
  276.            EventCounter := 1;
  277.            FileError := FSOpen('launch.next', vRefNum, LNRefNum);
  278.            FileError := GetEOF(LNRefNum, logicalEOF);
  279.            if (logicalEOF > 0) and (FileError = NoErr) then
  280.               begin 
  281.                       FileError := SetFPos(LNRefNum, fsFromStart, 0);
  282.                       LaunchCount := 0;
  283.                       while (LNChar <> chr(13)) and (LaunchCount <= logicalEOF) do
  284.                          begin { Start Structure LNChar <> chr(13) ... }
  285.                                  while (LNChar <> ',') and (LNChar <> chr(13)) and (LaunchCount <= logicalEOF) do
  286.                                     begin { Start Structure (LNChar <> ',' ... }
  287.                                             if (LNChar <> chr(255)) then
  288.                                                ThisEvent := concat(ThisEvent, LNChar);
  289.                                             LaunchCount := LaunchCount + 1;
  290.                                             Quantity := 1;
  291.                                             FileError := FSRead(LNRefNum, Quantity, @LNChar);
  292.                                             LNChar := chr(ord(LNChar) div 256);
  293.                                      end;            { End Structure (LNChar <> ',' ... }
  294.  
  295.                                   Event[EventCounter] := ThisEvent;
  296.                                   EventCounter := EventCounter + 1;
  297.                                   ThisEvent := '';
  298.                                   LNChar := chr(255)
  299.           end;            { End Structure (LNChar <> chr(13) ... }
  300.           
  301.                       FileError := FSClose(LNRefNum);
  302.                       FileError := FSDelete('launch.next', vRefNum);
  303.                       EventLimit := (EventCounter - 2);
  304.                       if EventLimit > 1 then
  305.                          begin { Start Structure EventLimit is > 1 }
  306.                                  FileError := Create('launch.next', vRefNum, 'QUED', 'TEXT');
  307.                                  FileError := FSOpen('launch.next', vRefNum, LNRefNum);
  308.                                  FileError := SetFPos(LNRefNum, fsFromStart, 0);
  309.                                  CharIndex := 0;
  310.                                  for EventCounter := 2 to EventLimit do
  311.                                     begin { Start Structure Launch.Next Counter Loop }
  312.                                             TempString := Event[EventCounter];
  313.                                             for CharCount := 1 to length(TempString) do
  314.                                                     TheChars[CharIndex + CharCount] := TempString[CharCount];
  315.                             
  316.                         CharIndex := CharIndex + length(TempString) + 1;
  317.                                              if EventCounter <> EventLimit then
  318.                                                      TheChars[CharIndex] := ','
  319.                                              else
  320.                                                      TheChars[CharIndex] := ENDLINE;
  321.                                      end; {End Structure Launch.Next Counter loop}
  322.  
  323.                                   FileError := FSWrite(LNRefNum, CharIndex, @TheChars);
  324.                                   FileError := FSClose(LNRefNum);
  325.                                   FileError := FlushVol(@volName, vRefNum);
  326.                           end; { End Structure EventLimit is > 1 }
  327.  
  328.                        if EventLimit > 0 then
  329.                                NextLaunch := Event[1];
  330.  
  331.                        TempString := NextLaunch;
  332.                        UprString(TempString, false);
  333.                        if TempString = 'BBS' then
  334.                           begin { Start Structure Special BBS to Application routine }
  335.                                   FileError := FSOpen('Tabby:Tabby Setup', vRefNum, SetupRef);
  336.                                   if FileError = NoErr then
  337.                                           FileError := GetEOF(SetupRef, logicalEOF);
  338.  
  339.                                    if (logicalEOF > 0) and (FileError = NoErr) then
  340.                                       begin { Start Structure Get BBS name from Tabby Setup }
  341.                                               FileError := SetFPos(SetupRef, fsFromStart, 0);
  342.                                               BBSName := '';
  343.                                               Quantity := 1;
  344.                                               BBSByte := 0;
  345.                                               SetupCount := 0;
  346.                                               while (BBSByte <> 13) and (SetupCount <= logicalEOF) do
  347.                                                  begin { Start Structure BBSByte <> 13 ... }
  348.                                                          FileError := FSRead(LNRefNum, Quantity, @BBSByte);
  349.                                                          if BBSByte <> 13 then
  350.                                                                  BBSName := concat(BBSName, chr(BBSByte));
  351.  
  352.                                                  end;        {    End Structure BBSByte <> 13 ... }
  353.  
  354.                                               FileError := FSClose(SetupRef);
  355.                                               NextLaunch := BBSName;
  356.                                       end        {    End Structure Get BBS name from Tabby Setup    }
  357.  
  358.                            end;        { End Structure Special BBS to Application routine }
  359.  
  360.                 end        { End Structure EventLimit is > 1 }
  361.  
  362.              else
  363.                 begin { Start Structure Delete Launch.next }
  364.                         FileError := FSClose(LNRefNum);
  365.                         FileError := FSDelete('launch.next', vRefNum)
  366.                 end;  { End Structure Delete Launch.next }
  367.  
  368.          { Is it an application?     }
  369.              FileError := GetFInfo(NextLaunch, vRefNum, fndrInfo);
  370.              if (FileError <> noErr) or (fndrInfo.fdType <> 'APPL') then
  371.                      NextLaunch := ''
  372.  
  373. end;            { End Structure HelloTurboTabby procedure }
  374.  
  375. end.            { End Unit Structure }
  376.